package cz.rosada.sx.library;

import java.util.ArrayList;
import java.util.List;

public class Fields {

    public List<Field> fields = new ArrayList<Field>();
	
	public String toSQL() {
		StringBuilder result = new StringBuilder();

		
		int primaryKeyCount = 0;
		result.append("(");
		for (Field field : fields) {
			result.append(field.toSQL() + ", ");
			if (field.mPrimaryKey)
				primaryKeyCount++;
		}

		if (primaryKeyCount > 0) {
			result.append("PRIMARY KEY (");
			for (Field field : fields) {
				if (field.mPrimaryKey)
					result.append(field.mName + ", ");
			}
			result.delete(result.length() - 2, result.length());
			result.append(")");
		} else
			result.delete(result.length() - 2, result.length());

		result.append(")");

		return result.toString();
	}

}
